package com.hwadee.teachingprocessmanagementsystem.service.base.impl;

import com.hwadee.teachingprocessmanagementsystem.entity.ExamSchedule;
import com.hwadee.teachingprocessmanagementsystem.dao.ExamScheduleDao;
import com.hwadee.teachingprocessmanagementsystem.service.base.ExamScheduleService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import jakarta.annotation.Resource;

/**
 * 考试安排表(ExamSchedule)表服务实现类
 *
 * @author makejava
 * @since 2024-07-11 14:20:03
 */
@Service("examScheduleService")
public class ExamScheduleServiceImpl implements ExamScheduleService {
    @Resource
    private ExamScheduleDao examScheduleDao;

    /**
     * 通过ID查询单条数据
     *
     * @param examId 主键
     * @return 实例对象
     */
    @Override
    public ExamSchedule queryById(Integer examId) {
        return this.examScheduleDao.queryById(examId);
    }

    /**
     * 分页查询
     *
     * @param examSchedule 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<ExamSchedule> queryByPage(ExamSchedule examSchedule, PageRequest pageRequest) {
        long total = this.examScheduleDao.count(examSchedule);
        return new PageImpl<>(this.examScheduleDao.queryAllByLimit(examSchedule, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param examSchedule 实例对象
     * @return 实例对象
     */
    @Override
    public ExamSchedule insert(ExamSchedule examSchedule) {
        this.examScheduleDao.insert(examSchedule);
        return examSchedule;
    }

    /**
     * 修改数据
     *
     * @param examSchedule 实例对象
     * @return 实例对象
     */
    @Override
    public ExamSchedule update(ExamSchedule examSchedule) {
        this.examScheduleDao.update(examSchedule);
        return this.queryById(examSchedule.getExamId());
    }

    /**
     * 通过主键删除数据
     *
     * @param examId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer examId) {
        return this.examScheduleDao.deleteById(examId) > 0;
    }

    /**
     * 通过课程编号获取数据
     * @param courseId
     * @return
     */
    @Override
    public ExamSchedule queryByCourseId(String courseId) {
        return this.examScheduleDao.queryByCourseId(courseId);
    }
}
